package com.quanxiaoha.weblog.common.service.impl;

import com.quanxiaoha.weblog.common.domain.entity.ScheduleReward;
import com.quanxiaoha.weblog.common.domain.mapper.ScheduleRewardMapper;
import com.quanxiaoha.weblog.common.domain.query.PaymentQuery;
import com.quanxiaoha.weblog.common.entity.SchedulePayment;
import com.quanxiaoha.weblog.common.domain.mapper.SchedulePaymentMapper;
import com.quanxiaoha.weblog.common.service.ISchedulePaymentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Roy
 * @since 2025-06-13
 */
@Service
public class SchedulePaymentServiceImpl extends ServiceImpl<SchedulePaymentMapper, SchedulePayment> implements ISchedulePaymentService {

    @Autowired
    private ScheduleRewardMapper scheduleRewardMapper;

    @Override
    public void savePayment(PaymentQuery query) {

        ScheduleReward scheduleReward = scheduleRewardMapper.selectById(query.getId());
        SchedulePayment schedulePayment = new SchedulePayment();
        schedulePayment.setRecordDate(scheduleReward.getRecordDate());
        schedulePayment.setCurrentCount(0);
        schedulePayment.setTotalCount(query.getCount());
        schedulePayment.setTotalReward(scheduleReward.getTotalReward());
        schedulePayment.setCreateTime(LocalDateTime.now());
        save(schedulePayment);
        scheduleReward.setTotalReward(0);
        scheduleRewardMapper.updateById(scheduleReward);
    }
}
